package com.hsu.common.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import com.hsu.common.core.domain.R;
import com.hsu.common.core.domain.TableDataInfo;

import java.util.List;

/**
 * @Author Hsu琛君珩
 * @Date 2025-03-25 13:49
 * @Description
 * @Version: v1.0.0
 */
public class BaseController {

    public R<Void> toR(int rows) {
        return rows > 0 ? R.ok() : R.fail();
    }

    public R<Void> toR(boolean result) {
        return result ? R.ok() : R.fail();
    }

    public TableDataInfo getTableDataInfo(List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        // 获取符合查询条件的数据的总数
        long total = new PageInfo<>(list).getTotal();
        return TableDataInfo.success(list, total);
    }

}
